package org.budo.dubbo.protocol.http.invocation.adapter.impl;

import java.lang.reflect.Method;

import org.budo.dubbo.protocol.http.invocation.adapter.ProtocolRequest;

/**
 * 上传的参数是一个json数组
 * 
 * @author lmw
 */
public class WebHttpArgumentArrayInvocationAdapter extends WebHttpInvocationAdapter {
    @Override
    public Object[] argumentArray(ProtocolRequest request, String requestBody, Method matchedMethod, Class<?> matchedInterface) {
        Object[] argumentArray = (Object[]) this.deserializeRequestBody(request, requestBody, matchedMethod, Object[].class);

        Class<?>[] parameterTypes = matchedMethod.getParameterTypes();

        Object[] parsedArguments = new Object[argumentArray.length];
        for (int index = 0; index < argumentArray.length; index++) {
            Class<?> parameterType = parameterTypes[index];
            Object argumentValue = argumentArray[index];
            parsedArguments[index] = this.parseArgumentValue(matchedInterface, matchedMethod, index, parameterType, argumentValue);
        }
        return parsedArguments;
    }
}